import random

# 用户信息
user_list = ['name', 'password', 'money', '用户居住地址', 'address']
user_dict = {}

# 判断账户是否存在
def decide():
    global user_dict
    global i
    global user_list
    if len(user_dict) <= 100:
        if i not in user_dict:
            print('1.账号信息不存在')
            id()
        else:
            print('2.账号信息已存在')
            password1 = input('请输入您的卡号密码：')
            if password1 != user_dict[i][1]:
                print('密码输入错误，请重新输入')
                decide()
            else:
                return
    else:
        print('3.银行用户库已满')
        exit()


# 随机生成卡号
def id():
    global i
    global user_dict
    global user_list
    i = random.randint(10000000, 100000000)
    name = input('为您办理新卡，请输入你的姓名：')
    password = input('请设置密码：')
    money = input('请输入您要存入的金额：')
    address = input('请输入您的居住地址：')
    print(f'为您办理的卡号是：{i}，%%%%%%%%%请您记牢%%%%%%%%%%')
    user_list[0] = name
    user_list[1] = password
    user_list[2] = money
    user_list[3] = address
    user_list[4] = "中国农业银行账户管理系统"

    user_dict[i] = user_list
    print(f'银行卡开户成功，卡号：{i},客户信息：{user_dict[i]}')

    use()


# 开户
def user():
    global i
    global user_dict
    global user_list
    i = random.randint(10000000, 100000000)
    decide()
    name = input('为您办理新卡，请输入你的姓名：')
    password = input('请设置密码：')
    money = input('请输入您要存入的金额：')
    address = input('请输入您的居住地址：')
    print(f'为您办理的卡号是：{i}，%%%%%%%%%请您记牢%%%%%%%%%%')
    user_list[0] = name
    user_list[1] = password
    user_list[2] = money
    user_list[3] = address
    user_list[4] = "中国农业银行账户管理系统"

    user_dict[i] = user_list
    print(f'银行卡开户成功，卡号：{i},客户信息：{user_dict[i]}')

    use()


# 存钱
def save_money():
    global i
    global user_dict
    global user_list
    i = int(input('请输入您要存款的银行卡号：'))
    decide()
    save = int(input('请输入您的存款金额：'))
    user_dict[i][2] = save + int(user_dict[i][2])
    print(f'您当前的余额为：{user_dict[i][2]}')

    use()


# 取钱
def cost_money():
    global i
    global user_dict
    global user_list
    i = int(input('请输入您要取款的银行卡号：'))
    decide()
    cost = int(input('请输入您的取款金额：'))
    user_dict[i][2] = int(user_dict[i][2]) - cost
    print(f'您当前的余额为：{user_dict[i][2]}')

    use()


# 转账
def enchange():
    global i
    global user_dict
    global user_list
    i = int(input('请输入您要转款的银行卡号：'))
    decide()
    cost = int(input('请输入您的转款金额：'))
    user_dict[i][2] = int(user_dict[i][2]) - cost
    print(f'您当前的余额为：{user_dict[i][2]}')
    i = int(input('请输入您要转款的银行卡号：'))
    decide()
    user_dict[i][2] = cost + int(user_dict[i][2])
    print(f'您当前的余额为：{user_dict[i][2]}')

    use()


# 查询
def search():
    global i
    global user_dict
    global user_list
    i = int(input('请输入您要查询的银行卡号：'))
    decide()
    print(
        f'当前账号：{i},密码:{user_dict[i][1]},余额：{user_dict[i][2]}元，用户居住地址：{user_dict[i][3]}，当前账户的开户行：中国XX银行XX支行')

    use()


def use():
    print('****************************************************')
    print('*               中国农业银行账户管理系统                *')
    print('****************************************************')
    print('                                                    ')
    print('*1.开户                                             *')
    print('*2.存钱                                             *')
    print('*3.取款                                             *')
    print('*4.转账                                             *')
    print('*5.查询                                             *')
    print('*6.Bye                                             *')
    print('****************************************************')
    use = int(input('请输入您要办理的业务:'))
    if use == 1:
        user()
    elif use == 2:
        save_money()
    elif use == 3:
        cost_money()
    elif use == 4:
        enchange()
    elif use == 5:
        search()
    elif use == 6:
        exit()


use()